import java.util.Scanner;

public class Main1393 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = 0;
        for (int i = 1; i <= n; i++) {
            int a = i / 100;//1
            int b = i / 10 % 10;
            int c = i % 10;
            if (i % 7 != 0 && a != 7 && b != 7 && c != 7) {
                x = x + i;
            }
        }
        System.out.println(x);
    }
}
